/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.tutwiz.model;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;

/**
 *
 * @author viktor
 */
@Entity
public class Comment implements Serializable, Comparable<Comment> {
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    @Column(nullable=false)
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date createdAt;
    
    @ManyToOne(optional=false, cascade=CascadeType.PERSIST)
    @JoinColumn(name="USER_FK")
    private User createdBy;
    @Column(nullable=false)
    private String text;
    @Column(nullable=false)
    private String title;
    
    @ManyToOne(optional=false)
    @JoinColumn(name="STEP_FK")
    private Step step;
      
    public Comment() {
    }
    

    public Comment(User createdBy, Step step, String title, String text) {
        this.createdBy = createdBy;
        this.step = step;
        this.title = title;
        this.text = text;
        this.createdAt = Calendar.getInstance().getTime();
    }
    
    public Long getId() {
        return id;
    }

    public Date getDate() {
        return createdAt;
    }

    public void setDate(Date date) {
        this.createdAt = date;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public User getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(User createdBy) {
        this.createdBy = createdBy;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public String toString() {
        return "net.tutwiz.model.Comment[ id=" + id + " ]";
    }

    @Override
    public int compareTo(Comment o) {
        return this.createdAt.compareTo(o.createdAt);
    }
    
}
